<?php ob_start();if(!isset($_SESSION)){
session_start();
}
require_once('Connections/microassur.php');require_once('utils/fonctions.php');?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
/*
$colname_rs_mod = "-1";
if (isset($_GET['Identifiant_refext'])) {
  $colname_rs_mod = $_GET['Identifiant_rib'];
}
if(isset($_GET['supp']))
{
mysql_query("START TRANSACTION");
$rq=mysql_query("delete  from rib where Identifiant_rib='".$colname_rs_mod."'");
if($rq)
{
mysql_query("commit"); 
}
else mysql_query("rollback"); 
*/


$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$bool=verifLibelle1("Code_banque_rib") && verifLibelle1("Code_guichet_rib") && verifLibelle1("Numero_compte_rib") &&  verifLibelle1("Cle_rib");
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && $bool) {
 mysql_select_db($database_microassur, $microassur);
 $idpers=-1;
$req=mysql_query("select * from role where Identifiant_contrat='".$_SESSION['idcontrat']."' and Type_role='S'") or die(mysql_error());
//echo $_SESSION['idcontrat'];

if($req && mysql_num_rows($req)){
$rep=mysql_fetch_array($req);
$idpers=$rep['Identifiant_personne'];}
if($idpers){

  $insertSQL = sprintf("INSERT INTO rib (Identifiant_rib, Code_banque_rib, Code_guichet_rib, Numero_compte_rib, Cle_rib, Etat_rib, Identifiant_personne) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['Identifiant_rib'], "int"),
                       GetSQLValueString($_POST['Code_banque_rib'], "text"),
                       GetSQLValueString($_POST['Code_guichet_rib'], "text"),
                       GetSQLValueString($_POST['Numero_compte_rib'], "text"),
                       GetSQLValueString($_POST['Cle_rib'], "text"),
                       GetSQLValueString("A", "text"),
                       GetSQLValueString($idpers, "int"));

  mysql_select_db($database_microassur, $microassur);
  mysql_query("START TRANSACTION");
  $Result1 = mysql_query($insertSQL, $microassur) or die(mysql_error());
  if(!$Result1){$message.="<br>Problème création RIB, contacter la DSI ";mysql_query("rollback");}
  else
  {mysql_query("commit");
  //header("location:rattacher.php?");
  $req=mysql_query("select max(Identifiant_rib)  as idrib from rib")or die(mysql_error());
	  if($req)
		{
			$rep=mysql_fetch_array($req);
			$idrib=$rep['idrib'];
			header("location : rattacherrib.php?Identifiant_rib=".$idrib);
		}
  }}
}
elseif((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && !$bool)
{

if(empty($_POST["Code_banque_rib"]))$message=colorer("Vous devez saisir le code banque ","false");
elseif(empty($_POST["Code_guichet_rib"]))$message=colorer("Vous devez saisir le code guichet  ","false");
elseif(empty($_POST["Numero_compte_rib"]))$message=colorer("Vous devez saisir le numéro compte","false");
elseif(empty($_POST["Cle_rib"]))$message=colorer("Vous devez saisir la clé rib","false");

elseif($verifLibelle1("Code_banque_rib"))$message=colorer("Le code banque saisi comporte des caractères spéciaux ","false");
elseif($verifLibelle1("Code_guichet_rib"))$message=colorer("Le code guichet saisi comporte des caractères spéciaux interdits ","false");
elseif($verifLibelle1("Numero_compte_rib"))$message=colorer("numéro compte saisi comporte des caractères spéciaux interdits ","false");
elseif($verifLibelle1("Cle_rib"))$message=colorer("La clé RIB saisi comporte des caractères spéciaux interdits ","false");


}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RIB</title>
			<link rel="stylesheet" type="text/css" href="../../../css/main.css" />
            <link rel="stylesheet" type="text/css" href="list.css" />
			<!--[if IE 7]>
            	<link rel="stylesheet" type="text/css" href="../../../css/ie7.css" />
            	<link rel="stylesheet" type="text/css" href="form_ie7.css" />
            <![endif]--></head>

<body>
<div id="sf_menu1">
<h3>Production </h3>
<?php
	

	if(isset($message) && !empty($message)){
		echo $message;
	}
	$nommodule="RIB";
	//$nommodule2="Liste des adresse";
	$nom_module_saisie="Ecran saisie";
?>
</div>
<div class="cleared"></div>

<div class="corps1">
<div class="cleared"></div>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"><div class="imgleft"></div>
	<div class="imgmiddle">
    <div class="btn">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nommodule; ?></h5>
        </span><span class="btnright"></span>
    </div>
  	<div class="btn1">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nom_module_saisie; ?></h5>
        </span>
        <span class="btnright"></span>
    </div>
	<div class="formulaire">
  <table class="tabform">
    <tr >
      <td  class="td1">CODE BANQUE</td>   
      <td><input name="Code_banque_rib" type="text" value="" size="32" maxlength="5" /></td>
    </tr>
    <tr >
      <td class="td1">GUICHET</td>
      <td><input name="Code_guichet_rib" type="text" value="" size="32" maxlength="5" /></td>
    </tr>
    <tr >
      <td class="td1">NUMERO DE COMPTE</td>
      <td><input name="Numero_compte_rib" type="text" value="" size="32" maxlength="11" /></td>
    </tr>
    <tr >
      <td class="td1">CLE RIB</td>
      <td><input name="Cle_rib" type="text" value="" size="32" maxlength="2" /></td>
       </tr>
  </table>

       </div>
    
 </div>

<div class="imgright"></div>				
<div class="cleared"></div>
    
    
    <div class="bt1"> <a href="index.php?Identifiant_personne=<?php echo $_GET['Identifiant_personne']?>"><span class="btleft"></span>
        <span class="btmiddle">Retour</span>
        <span class="btright"></span>
    </a></div>
    
      <div class="bt">
	<span class="btleft"></span><input type="submit" value="Valider" class="resizeall btmiddle"/>
    <span class="btright"></span></div>
    
	 
  
       <div class="cleared"></div>


  <input type="hidden" name="Identifiant_rib" value="" />
  <input type="hidden" name="Etat_rib" value="" />
  <input type="hidden" name="Identifiant_personne" value="" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
</div>
</body>
</html>
<?php ob_end_flush();?>